package com.zimmor.annotation;

import java.lang.reflect.Method;

/**
 * @Author:zimmor
 * @Date: 2021/11/8 10:04
 * @Description 对@MethodAnnotation注解的处理
 * @version: 1.0.0
 */

public class MethodAnnotationInit {
    public static void main(String[] args) throws Exception {
        //通过反射得到使用了MethodAnnotation这个注解的类的class文件
        Class<MethodAnnotationDemo> clazz = MethodAnnotationDemo.class;
        Method[] methods = clazz.getDeclaredMethods();
        for (Method method : methods) {
            boolean annotationPresent = method.isAnnotationPresent(MethodAnnotation.class);
            System.out.println("annotationPresent = " + annotationPresent);
            if(annotationPresent) {
                method.invoke(clazz.getConstructor().newInstance());
            }
        }


    }
}
